package com.sino.androiddesign.anim.objectanimator

import android.animation.ValueAnimator
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View

 class MyView :View{
    private var mPaint:Paint? = null

    private val RADIUS :Float = 70f
    private var currentPoint: Point? = null

    constructor(context: Context):this(context,null)
    constructor(context: Context,attr: AttributeSet?):super(context,attr){
        mPaint = Paint(Paint.ANTI_ALIAS_FLAG)
        mPaint!!.color =Color.BLUE
    }

    override fun onDraw(canvas: Canvas?) {
        if (currentPoint === null){
            currentPoint = Point(RADIUS,RADIUS)
            canvas!!.drawCircle(currentPoint!!.x,currentPoint!!.y,RADIUS,mPaint)

            //将属性动画作用到view中
            val startPoint = Point(RADIUS,RADIUS)
            val endPoint =Point(400f,70f)
            val animator = ValueAnimator.ofObject(PointEvaluator(), startPoint, endPoint)
            animator.duration =5000
            animator.addUpdateListener { animation ->
               currentPoint =  animation.animatedValue as Point

                postInvalidate()
            }
            animator.start()
        }else{
         canvas!!.drawCircle(currentPoint!!.x,currentPoint!!.y,RADIUS,mPaint)
        }
    }
}